package com.rqf.mr.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.rqf.mr.service.ILoginService;
import com.rqf.mr.service.impl.LoginService;
import com.server.web.JSONSerielizer;
import com.server.web.OutputUtil;


/**
 * 登录相关
 * @author HelloWorld_luo
 * @date 2016年4月18日
 */
@Controller
@RequestMapping("login")
public class LoginController {
	
	@Autowired
	private ILoginService loginService;
	
	@RequestMapping("byPwd/{name}/{password}")
	public void login(HttpServletRequest request, 
			HttpServletResponse response,@PathVariable String name,
			@PathVariable String password){
		Boolean isSuccess = loginService.login(name, password);
		OutputUtil.returnJsonp(request, response, isSuccess.toString());
	}
	
	@RequestMapping("department")
	public void department(HttpServletRequest request, 
			HttpServletResponse response){
		List<Map<String, Object>> list = loginService.searchDepartmentInfo();
		String json = JSONSerielizer.toJson(list, null, null);
		OutputUtil.returnJsonp(request, response, json);
	}
	
	@RequestMapping("nurseInfo/{nurseLoginId}")
	public void nurseInfo(HttpServletRequest request, 
			HttpServletResponse response , @PathVariable String nurseLoginId){
		List<Map<String, Object>> list = loginService.getNurseInfo(nurseLoginId);
		String json = JSONSerielizer.toJson(list.get(0), null, null);
		OutputUtil.returnJsonp(request, response, json);
	}
	 
}
